package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.dto.RetailImmunizationRecordDto;
import com.jiantong.work.impl.manager.RetailImmunizationRecordManager;
import com.jiantong.work.service.RetailImmunizationRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by mz on 18/9/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class RetailImmunizationRecordWriteServiceImpl implements RetailImmunizationRecordWriteService{

    private final RetailImmunizationRecordManager retailImmunizationRecordManager;

    @Autowired
    public RetailImmunizationRecordWriteServiceImpl(RetailImmunizationRecordManager retailImmunizationRecordManager) {
        this.retailImmunizationRecordManager = retailImmunizationRecordManager;
    }

    /**
     * 新建一条散户的免疫记录
     *
     * @param retailImmunizationRecordDto 免疫记录对象
     * @return Long
     */
    @Override
    public Response<Long> create(RetailImmunizationRecordDto retailImmunizationRecordDto,Integer toStatus) {
        try{
            return Response.ok(retailImmunizationRecordManager.create(retailImmunizationRecordDto,toStatus));
        }catch (Exception e){
            log.error("failed to create this report, case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to create this report");
        }
    }

    /**
     * 更新散户的免疫记录
     *
     * @param retailImmunizationRecordDto 免疫记录对象
     * @return Boolean
     */
    @Override
    public Response<Boolean> update(RetailImmunizationRecordDto retailImmunizationRecordDto , Integer toStatus) {
        try{
            return Response.ok(retailImmunizationRecordManager.update(retailImmunizationRecordDto,toStatus));
        }catch (Exception e) {
            log.error("failed to update this report , case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update this report");
        }
    }
}
